<template>
  <div class="login">
    <h1>登录页面</h1>
    <p>
      用户名:
      <input type="text" v-model="form.adminname" />
    </p>
    <p>
      密&nbsp;&nbsp;&nbsp;码:
      <input type="password" v-model="form.password" />
    </p>

    <p>
      <input type="button" value="登录" @click="login" />
    </p>
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";
import service from "../../../utils/service";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";

const $router = useRouter();

interface ilogin {
  adminname: string;
  password: string;
}

const form = reactive<ilogin>({
  adminname: "",
  password: "",
});
const login = () => {
  service({
    url: "/admin/login",
    method: "post",
    data: {
      form,
    },
  }).then((res) => {
    if(!form.adminname&&!form.password){
        // ElMessage({
        //   message: "请输入用户名和密码",
        //   type: "warning",
        // });
    }
      else if (form.adminname == "admin" && form.password == "123456") {
        ElMessage({
          message: "登录成功",
          type: "success",
        });
        localStorage.setItem("adminname", form.adminname);
        $router.push("/Admin/list2");
      }  else if (form.password != "123456") {
        ElMessage({
          message: "密码错误",
          type: "error",
        });
      } else if (form.adminname != "admin") {
        ElMessage({
          message: "未注册",
          type: "warning",
        });
      }
  });
};
login();
</script>

<style scope>
.login input{
  margin-top: 20px;
}
</style>